<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.3.0: http://docutils.sourceforge.net/" />
<title>vb2Py - Select</title>
<link rel="stylesheet" href="default.css" type="text/css" />
</head>
<body>
<div class="document" id="vb2py-select">
<h1 class="title">vb2Py - Select</h1>
<!-- filename: c:\development\python22\lib\site-packages\vb2py\doc/select.htm -->
<p>Contents of this page:</p>
<ul class="simple">
<li><a class="reference" href="#general">General</a></li>
<li><a class="reference" href="#default-conversion">Default Conversion</a></li>
<li><a class="reference" href="#list-of-options">List of Options</a></li>
</ul>
<p>Specific options:</p>
<ul class="simple">
<li><a class="reference" href="#evaluatevariable">EvaluateVariable</a></li>
<li><a class="reference" href="#selectvariableprefix">SelectVariablePrefix</a></li>
<li><a class="reference" href="#usenumericindex">UseNumericIndex</a></li>
</ul>
<div class="section" id="general">
<h1><a name="general">General</a></h1>
<p><tt class="literal"><span class="pre">Select</span></tt> blocks are replaced by <tt class="literal"><span class="pre">if/elif/else</span></tt> blocks. By default a <tt class="literal"><span class="pre">select</span></tt> variable 
is created, which is used in subsequent tests. This means that the checked value is
only evaluated once per <tt class="literal"><span class="pre">select</span></tt> and not once per condition. If this is not an issue then
an option allows the value to be evalutated each time as required. Also by default, a numeric index is appended to the select variable to prevent clashed for nested <tt class="literal"><span class="pre">Select</span></tt> constructs.</p>
<p>The conversion handles multiple values per case and even range settings.</p>
</div>
<div class="section" id="default-conversion">
<h1><a name="default-conversion">Default Conversion</a></h1>
<table style="code-table"><tr><th class="code-header">VB</th><th class="code-header">Python</th></tr><tr><td class="vb-code-cell"><pre><br>Select Case Value<br>    Case 1<br>        DoOne<br>    Case 2<br>        DoTwo<br>    Case 3, 4<br>        DoThreeOrFour<br>    Case 5 To 10<br>        DoFiveToTen<br>    Case Else<br>        DoElse<br>End Select<br></pre></td><td class="python-code-cell"><pre><br><br><br><br>    _select5 = Value<br>    if (_select5 == 1):<br>        DoOne()<br>    elif (_select5 == 2):<br>        DoTwo()<br>    elif (_select5 == 3) or (_select5 == 4):<br>        DoThreeOrFour()<br>    elif (5 <= _select5 <= 10):<br>        DoFiveToTen()<br>    else:<br>        DoElse()<br></pre></td></tr></table>
</div>
<div class="section" id="list-of-options">
<h1><a name="list-of-options">List of Options</a></h1>
<p>Here are the options in the INI file:</p>
<pre class="literal-block">
[Select]
# Once or EachTime, how many times to evaluate the case variable  
EvaluateVariable = Once
# Name of select variable (only used if EvaluateVariable is Once)
SelectVariablePrefix = _select
# Yes or No, use numeric index on select variable (needed if you every have nested Selects and EvaluateVariable = Once)
UseNumericIndex = Yes
</pre>
<div class="section" id="evaluatevariable">
<h2><a name="evaluatevariable">EvaluateVariable</a></h2>
<p>Syntax: <tt class="literal"><span class="pre">EvaluateVariable</span> <span class="pre">=</span> <span class="pre">Once</span> <span class="pre">|</span> <span class="pre">EachTime</span></tt></p>
<p>The default behaviour is to evaluate the select expression once at the start of the block. By setting this option to <tt class="literal"><span class="pre">EachTime</span></tt> you can force the expression to be evaluated for each <tt class="literal"><span class="pre">if/elif</span></tt> statement. This generally looks cleaner but can lead to undesired side effects or slow run times depending on how expensive <a class="footnote-reference" href="#id2" id="id1" name="id1"><sup>1</sup></a> the expression is to calculate.</p>
<table style="code-table"><tr><th class="code-header">VB</th><th class="code-header">Python</th></tr><tr><td class="vb-code-cell"><pre><br>' VB2PY-Set: Select.EvaluateVariable = EachTime<br>Select Case Value<br>    Case 1<br>        DoOne<br>    Case 2<br>        DoTwo<br>    Case 3, 4<br>        DoThreeOrFour<br>    Case 5 To 10<br>        DoFiveToTen<br>    Case Else<br>        DoElse<br>End Select<br>' VB2PY-Unset: Select.EvaluateVariable<br></pre></td><td class="python-code-cell"><pre><br><br><br><br>    if (Value == 1):<br>        DoOne()<br>    elif (Value == 2):<br>        DoTwo()<br>    elif (Value == 3) or (Value == 4):<br>        DoThreeOrFour()<br>    elif (5 <= Value <= 10):<br>        DoFiveToTen()<br>    else:<br>        DoElse()<br></pre></td></tr></table>
</div>
<div class="section" id="selectvariableprefix">
<h2><a name="selectvariableprefix">SelectVariablePrefix</a></h2>
<p>Syntax: <tt class="literal"><span class="pre">SelectVariablePrefix</span> <span class="pre">=</span> <span class="pre">name</span></tt></p>
<p>When <a class="reference" href="#evaluatevariable">EvaluateVariable</a> is set to <tt class="literal"><span class="pre">Once</span></tt>, this option determines the prefix used to name the variable used in the select. If <a class="reference" href="#usenumericindex">UseNumericIndex</a> is set to <tt class="literal"><span class="pre">No</span></tt> then this option sets the variable name used, otherwise this is the prefix and the final variable will also include a unique ID number.</p>
<table style="code-table"><tr><th class="code-header">VB</th><th class="code-header">Python</th></tr><tr><td class="vb-code-cell"><pre><br>' VB2PY-Set: Select.SelectVariablePrefix = selectVariable<br>Select Case Value<br>    Case 1<br>        DoOne<br>    Case 2<br>        DoTwo<br>    Case 3, 4<br>        DoThreeOrFour<br>    Case 5 To 10<br>        DoFiveToTen<br>    Case Else<br>        DoElse<br>End Select<br>' VB2PY-Unset: Select.SelectVariablePrefix<br></pre></td><td class="python-code-cell"><pre><br><br><br><br>    selectVariable7 = Value<br>    if (selectVariable7 == 1):<br>        DoOne()<br>    elif (selectVariable7 == 2):<br>        DoTwo()<br>    elif (selectVariable7 == 3) or (selectVariable7 == 4):<br>        DoThreeOrFour()<br>    elif (5 <= selectVariable7 <= 10):<br>        DoFiveToTen()<br>    else:<br>        DoElse()<br></pre></td></tr></table>
</div>
<div class="section" id="usenumericindex">
<h2><a name="usenumericindex">UseNumericIndex</a></h2>
<p>Syntax: <tt class="literal"><span class="pre">UseNumericIndex</span> <span class="pre">=</span> <span class="pre">Yes</span> <span class="pre">|</span> <span class="pre">No</span></tt></p>
<p>When <a class="reference" href="#evaluatevariable">EvaluateVariable</a> is set to <tt class="literal"><span class="pre">Once</span></tt>, this option determines whether a unique ID number is appended to the <a class="reference" href="#selectvariableprefix">SelectVariablePrefix</a> to determine the variable name used to hold the select expression. If used, the index is incremented for each <tt class="literal"><span class="pre">select</span></tt> constuct found. This option is always required to be <tt class="literal"><span class="pre">Yes</span></tt> where the code includes nested <tt class="literal"><span class="pre">Select</span></tt> blocks <em>and</em> <a class="reference" href="#evaluatevariable">EvaluateVariable</a> is set to <tt class="literal"><span class="pre">Once</span></tt>. If neither of these conditions applies then it is safe to set this to <tt class="literal"><span class="pre">No</span></tt></p>
<table style="code-table"><tr><th class="code-header">VB</th><th class="code-header">Python</th></tr><tr><td class="vb-code-cell"><pre><br>' VB2PY-Set: Select.UseNumericIndex = No<br>Select Case Value<br>    Case 1<br>        DoOne<br>    Case 2<br>        DoTwo<br>    Case 3, 4<br>        DoThreeOrFour<br>    Case 5 To 10<br>        DoFiveToTen<br>    Case Else<br>        DoElse<br>End Select<br>' VB2PY-Unset: Select.UseNumericIndex<br></pre></td><td class="python-code-cell"><pre><br><br><br><br>    _select = Value<br>    if (_select == 1):<br>        DoOne()<br>    elif (_select == 2):<br>        DoTwo()<br>    elif (_select == 3) or (_select == 4):<br>        DoThreeOrFour()<br>    elif (5 <= _select <= 10):<br>        DoFiveToTen()<br>    else:<br>        DoElse()<br></pre></td></tr></table>
<hr />
<table class="footnote" frame="void" id="id2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1" name="id2">[1]</a></td><td>Expensive as in CPU time.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
